<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+index ">
					<image :src="item.url" mode="aspectFill"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" @click="navItemClick1()">
				<image src="@/static/nav/shufa.png" class="icon"></image>
				<text>书法</text>
			</view>
			<view class="nav-item" @click="navItemClick1()">
				<image src="@/static/nav/biancheng.png" class="icon"></image>
				<text>编程</text>
			</view>
			<view class="nav-item" @click="navItemClick1()">
				<image src="@/static/nav/huahua.png" class="icon"></image>
				<text>画画</text>
			</view>
			<view class="nav-item" @click="navItemClick1()">
				<image src="@/static/nav/jimu.png" class="icon"></image>
				<text>积木</text>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image :src="item.floor_title.image_src" class="floor-title"></image>
				<view class="floor-image-box">
					<navigator :url="item.product_list[0].url" class="left-image-box">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="right-image-box">
						<navigator :url="item1.url" class="right-image-item" v-for="(item1,index1) in item.product_list" :key="index1" >
							<image v-if="index1!==0" :style="{width:item1.image_width+'rpx'}" 
							:src="item1.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				swiperList:[],
				navList:[],
				floorList:[]
			};
		},
		onLoad(){
			this.getSwiperList()
			this.getFloorList()
		},
		methods:{
			async getSwiperList(){
				uni.request({
					url:'http://localhost:8080/yzmimage/home_banner',
					method:'GET',
					data:{},
					dataType:'json',
					sslVerify:true,
					success: (res) => {
						if(res.data.code !==200){
							this.$showMsg()
						}else{
							console.log(res)
							this.$showMsg('请求成功！')
							this.swiperList = res.data.data
						}
						console.log(res)
					}
				})
				// const res = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res)
			},
						
			async getFloorList(){
				uni.request({
					url:'http://localhost:8080/yzmimage/home_banner',
					method:'GET',
					data:{},
					dataType:'json',
					sslVerify:true,
					success: (res) => {
						if(res.data.code !==200){
							this.$showMsg()
						}else{
							console.log(res)
							this.$showMsg('请求成功！')
							this.getFloorList = res.data.data
						}
						console.log(res)
					}
				})
			},
			navItemClick(item){
				if(item.name === "分类"){
					uni.switchTab({
						url:'/pages/cate/cate'
					})
				}
			},
		}
	}
</script>

<style lang="scss">
swiper{
	height: 330rpx;
	.swiper-item,
	image{
		width: 100%;
		height: 100%;
	}
}
.nav-list{
	display: flex;
	justify-content: space-around;
	margin: 16px 0;
	.nav-item{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 10px 0;
		font-size: 13px;
		.icon{
			width: 35px;
			height: 35px;
			padding-bottom:5px;
		}
	}
}

.floor-list{
	.floor-title{
		display: flex;
		width: 100%;
		height: 60rpx;
	}
}

.floor-image-box{
	display: flex;
	padding-left: 10rpx;
	.left-image-box{
		flex:1
	}
	.right-image-box{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
}

</style>
